package com.xigua._递归;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 泰波那契序列 Tn 定义如下： 
 *T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
 *给你整数 n，请返回第 n 个泰波那契数 Tn 的值。
 *
 *
 * @date 2022/3/2620:01
 */
public class _1137_第N个泰波那契数 {

    public int tribonacci(int n) {
        if (n<2) return n;
        if (n<3) return 1;
        int first = 0;
        int second = 1;
        int third = 1;
        for (int i = 3; i <= n; i++) {
            int sum = first + second + third;
            first = second;
            second = third;
            third = sum;
        }
        return third;

    }
}
